package controller.validator;

import java.util.ArrayList;

import exception.InputValidationErrors;

/**
 * Implements validation for adding, updating or deleting prerequisite.
 * 
 * @author huangjm.2012, jaslin.wee.2012
 * 
 */
public class PreRequisiteValidator extends Validator {
	private String courseCode;
	private String preRequisiteCode;

	public String getCourseCode() {
		return courseCode;
	}

	public String getPreRequisiteCode() {
		return preRequisiteCode;
	}

	public PreRequisiteValidator(String preRequisiteCode, String courseCode) {
		this.courseCode = courseCode;
		this.preRequisiteCode = preRequisiteCode;
	}

	@Override
	public void performValidationBeforeAdding() throws InputValidationErrors {
		/*
		 * Array list to store logic error messages
		 */
		ArrayList<String> logicErrors = new ArrayList<String>();

		/*
		 * Validation for invalid course
		 */
		try {
			checkForCourse(courseCode);
		} catch (Exception e) {
			logicErrors.add(Validator.INVALID_COURSE);
		}

		/*
		 * Validation for invalid prerequisite
		 */
		try {
			checkForCourse(preRequisiteCode);
		} catch (Exception e) {
			logicErrors.add(Validator.INVALID_PREREQUISITE);
		}

		/*
		 * Throw exception
		 */
		if (!logicErrors.isEmpty()) {
			throw new InputValidationErrors(logicErrors);
		}
	}

	@Override
	public void performValidationBeforeUpdating() throws InputValidationErrors {
		// TODO Auto-generated method stub

	}

	@Override
	public void performValidationBeforeDeleting() throws InputValidationErrors {
		// TODO Auto-generated method stub

	}

}
